package com.wondertek.poms.core.service.impl;//package com.wondertek.poms.core.service.impl;
//
//import com.wondertek.poms.common.service.impl.ServiceImpl;
//import com.wondertek.poms.core.service.IPcPrdInfoRateChargeService;
//import com.wondertek.poms.dao.po.PcPrdInfoRateCharge;
//import com.wondertek.poms.dao.pojo.PcPrdInfoRateChargePojo;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.domain.Page;
//import org.springframework.data.domain.PageImpl;
//import org.springframework.data.domain.Pageable;
//import org.springframework.stereotype.Service;
//
//import javax.persistence.EntityManager;
//import javax.persistence.Query;
//import java.math.BigDecimal;
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * @author evan0213
// * @description
// */
//@Service
//public class PcPrdInfoRateChargeServiceImpl extends ServiceImpl<PcPrdInfoRateCharge, Long> implements IPcPrdInfoRateChargeService {
//
//	@Autowired
//	private EntityManager entityManager;
//
//	@Override
//	public PcPrdInfoRateCharge deleteLogic(Long id) {
//		return null;
//	}
//
//	@Override
//	public PcPrdInfoRateCharge merge(PcPrdInfoRateCharge model) {
//		return null;
//	}
//
//	//根据计费id查询码率收费列表的查询sql
//	private String chargePointSql = "SELECT\n" +
//			"\tCPT.PRICE,\n" +      //售价
//			"\tCP.CHANNEL_PACKAGE_NAME,\n" +    //渠道包名
//			"\tPIRC.CHARGE_POINT_ID,\n" +   //计费id
//			"\tCPT.CHARGE_NAME,\n" +       //计费名称
//			"\tPIRC.ID,\n" +         //基本计费id
//			"\tCPT.CHARGE_MODE,\n" +   //计费方式
//			"\tPIRC.RATE_LABEL,\n" +   //码率标签
//			"\tCP.CHANNEL_ID,\n" +     //渠道id
//			"\tCPT.DESCRIPTION,\n" +    //计费描述
//			"\tCP.ID AS CHANNEL_PKG_ID\n" +               //渠道包id
//			"\tFROM\n" +
//			"\t PC_PRD_INFO_RATE_CHARGE PIRC\n" +
//			"\tLEFT JOIN PC_CHANNEL_PACKAGE CP ON PIRC.CHANNEL_PACKAGE_ID = CP.ID \n" +
//			"\tLEFT JOIN PC_CHARGE_POINT CPT ON PIRC.CHARGE_POINT_ID = CPT.ID \n" +
//			"\tWHERE PIRC.DELETED=0 AND PIRC.CHARGE_POINT_ID IS NOT NULL ";
//
//	//根据权益节点查询码率收费列表的查询sql
//	private String equityNodeSql = "SELECT\n" +
//			"\tCP.CHANNEL_PACKAGE_NAME,\n" +    //渠道包名
//			"\tPIRC.EQUITY_ID,\n" +    //权益节点id
//			"\tCPG.GROUP_NAME,\n" +    //产品组名
//			"\tEN.CODE,\n" +           //权益节点编码
//			"\tPIRC.ID,\n" +   //基本计费id
//			"\tPIRC.RATE_LABEL,\n" +   //码率标签
//			"\tCP.CHANNEL_ID,\n" +     //渠道id
//			"\tCP.ID AS CHANNEL_PKG_ID \n" +                //渠道包id
//			"\tFROM\n" +
//			"\tPC_PRD_INFO_RATE_CHARGE PIRC\n" +
//			"\tLEFT JOIN PC_CHANNEL_PACKAGE CP ON PIRC.CHANNEL_PACKAGE_ID = CP.ID \n" +
//			"\tLEFT JOIN PC_EQUITY_NODE EN ON PIRC.EQUITY_ID = EN.ID \n" +
//			"\tLEFT JOIN PC_CHARGE_POINT_GROUP CPG ON EN.CPG_ID = CPG.ID \n" +
//			"\tWHERE PIRC.DELETED=0 AND PIRC.EQUITY_ID IS NOT NULL ";
//
//	@Override
//	public Page<PcPrdInfoRateChargePojo> getRateChargeList(PcPrdInfoRateCharge prdInfoRateCharge, int page, int rows, String sord, String sidx) {
//		String chargePointCondition = chargePointSqlWhere(prdInfoRateCharge);
//		String equityNodeCondition = equityNodeSqlWhere(prdInfoRateCharge);
//		Pageable pageable = getPageable(page - 1, rows, sidx, sord);
//		BigDecimal count1 = (BigDecimal) entityManager.createNativeQuery("select  count(*) from ( " + chargePointCondition + " ) ").getSingleResult();
//		BigDecimal count2 = (BigDecimal) entityManager.createNativeQuery("select  count(*) from ( " + equityNodeCondition + " ) ").getSingleResult();
//		List<PcPrdInfoRateChargePojo> result = new ArrayList<>();
//		StringBuilder conditionOrder = sqlStringOrder(sord, sidx);
//		if (count1.longValue() > 0L) {
//			Query query1 = entityManager.createNativeQuery(chargePointCondition + conditionOrder.toString());
//			List<Object[]> resultList1 = query1.getResultList();
//			List<PcPrdInfoRateChargePojo> list1 = getRateChargePojoListByChargePointId(resultList1);
//			result.addAll(list1);
//		}
//		if (count2.longValue() > 0L) {
//			Query query2 = entityManager.createNativeQuery(equityNodeCondition + conditionOrder.toString());
//			List<Object[]> resultList2 = query2.getResultList();
//			List<PcPrdInfoRateChargePojo> list2 = getRateChargePojoListByEquityId(resultList2);
//			result.addAll(list2);
//		}
//		return new PageImpl<>(result, pageable, count1.longValue() + count2.longValue());
//	}
//
//	private String chargePointSqlWhere(PcPrdInfoRateCharge prdInfoRateCharge) {
//		StringBuilder condition = new StringBuilder();
//		if (prdInfoRateCharge.getPrdInfoId() != null) {
//			condition.append(chargePointSql)
//					.append("AND PIRC.PRD_INFO_ID = ")
//					.append(prdInfoRateCharge.getPrdInfoId().toString());
//		}
//		return condition.toString();
//	}
//
//	private String equityNodeSqlWhere(PcPrdInfoRateCharge prdInfoRateCharge) {
//		StringBuilder condition = new StringBuilder();
//		if (prdInfoRateCharge.getPrdInfoId() != null) {
//			condition.append(equityNodeSql)
//					.append("AND PIRC.PRD_INFO_ID = ")
//					.append(prdInfoRateCharge.getPrdInfoId().toString());
//		}
//		return condition.toString();
//	}
//
//}
